function clearEmptyNode(nodes){
	if(!nodes || typeof(nodes)=='string'){return nodes;}
	var result = [];
	for(var i in nodes){
		var node = nodes[i];
		if(node!=null && node.isHidden != true){
			result.push(node);
		}
	}
	return result;
}
function isHalf(n) {
	if(n && n.use==false){
		if (n && n.checked && n.halfCheck) {
			return true;
		}
	}
	if (n.getCheckStatus() && n.getCheckStatus().checked && n.getCheckStatus().half) {
		return true;
	}
	return false;
}
function isChecked(n) {
	if(n && n.use==false){
		if (n && n.checked && !n.halfCheck) {
			return true;
		}
	}
	if (n.getCheckStatus() && n.getCheckStatus().checked && !n.getCheckStatus().half) {
		return true;
	}
	return false;
}
function getNodePath(node,sp) {
	if (!node) {return "";}
	sp = sp||'>';
	var path = node.name;
	while (node.getParentNode()) {
		node = node.getParentNode();
		path = node.name + sp + path;
	}
	return path;
}
function getCheckedMainNodes(nodes) {
	if(typeof(nodes) === 'string'){
		var treeId = nodes;
		nodes = getCheckedNodes(treeId);
	}
	var main = [];
	for (var i = 0; i < nodes.length; i++) {
		var cur = nodes[i], parent = cur.getParentNode();
		if (cur && !isChecked(cur)) {continue;}
		if (parent && !isChecked(parent)) {
			main.push(cur);
		}
		if (!parent && isChecked(cur)) {
			main.push(cur);
		}
		// if(!cur.isParent){main.push(cur);}
	}
	return main;
}
function getCheckedNodes(zTree) {
	return  $.fn.zTree.getZTreeObj(zTree).getCheckedNodes(true);
}
function getCheckedLeaf(zTree) {
	var leaf = [];
	var treeObj = $.fn.zTree.getZTreeObj(zTree);
	if(!isnull(treeObj)){
		var nodes = treeObj.getCheckedNodes(true);
		if (nodes) {
			for (var i = 0; i < nodes.length; i++) {
				if (!nodes[i].isParent) {
					leaf.push(nodes[i]);
				}
			}
		}
	}
	return leaf;
}
function delChecked(zTree,nodeTid,callback){
	zTree = $.fn.zTree.getZTreeObj(zTree);
	if(zTree && nodeTid){
		var node = zTree.getNodeByTId(nodeTid);
		if(node){
			node.checked = false;
			zTree.updateNode(node,true);
			var children = node.children;
			if(children){
				for (var i = 0; i < children.length; i++) {
					children[i].checked = false;
					zTree.updateNode(children[i],true);
				}
			}
			callback(zTree,nodeTid);
		}
	}
}
function changeCheckType(zTree,checkType){
	if($.fn.zTree.getZTreeObj(zTree).setting.check.chkStyle!=checkType){
		$.fn.zTree.getZTreeObj(zTree).setting.check.chkStyle=checkType;
		$('.ztree',$css.focusDialog()||$.cssTab.focus()|| document).find('span').mouseout();
	}
}
function expandNode(zTree,nodeId,callback){
	var tree = $.fn.zTree.getZTreeObj(zTree);
	if(tree && nodeId){
		var node =  tree.getNodeByParam("id", nodeId, null);
		if(node){
			tree.expandNode(node.getParentNode(),true,false,true,false);
			if(callback && typeof(callback)=='function'){
				callback(node);
			}else{
				$('#'+zTree+'.ztree .sel').removeClass('sel').css('border','');
				$('#'+zTree+'.ztree #' +node.tId+ '_a').addClass('sel')
					.css('border-color','#41baf2')
					.css('border-style','solid')
					.css('border-width','1px');
			}
		}
	}
}